app.factory('utilService', function($http) {

    return {

    	ajax: function(params, $scope) {

			var postCfg;
			
			$scope.showLoading = true;
			
			if(params.method == 'post'){
				var postCfg = {  
			        headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},  
			        transformRequest: function(data){
			        	return $.param(data);
			        }
			    }; 
			    $http.post(params.url, params.data || {}, postCfg).success(function(response){
			    	params.ok && params.ok(response);
					$scope.showLoading = false;
			    });
			}else{
				$http({
					url: params.url,
					method: "get",
					params: params.data || {}
				}).success(function(response) {
					params.ok && params.ok(response);
					$scope.showLoading = false;
				})
			}
    	},

    	fill0: function(num) {
    		return num < 10 ? '0' + num : num;
    	}

    };

});